import {
  IMG_PATH
} from '../../../../config/index.js'
import { getAnalysisIdCard } from "../../../../utils/util.js"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    educatestartShow:false,
    educateendShow:false,
    currentDate: new Date().getTime(),
    minDate: new Date(1920, 1, 1).getTime(),
    maxDate: new Date(2050, 1, 1).getTime(),
    statusBarHeight:"",
    IMG_PATH:IMG_PATH,
    personalUrl:`${IMG_PATH}/editjianli/geren.png`,
    workUrl:`${IMG_PATH}/editjianli/gongzuo.png`,
    educateUrl:`${IMG_PATH}/editjianli/jiaoyu.png`,
    familyUrl:`${IMG_PATH}/editjianli/jiating.png`,
    jinjilianxiyUrl:`${IMG_PATH}/editjianli/jinjilianxi.png`,
    zongjieUrl:`${IMG_PATH}/editjianli/gerenzongjie.png`,
    dataList:[],
    havetoActive: ['1'],
    nohaveActive: ['1'],
    username:'',
    birthday:'',
    sex:'',
    jiguan:'请选择',
    xueli:'请选择',
    identifycode:'',
    formatter(type, value) {
      if (type === 'year') {
        return `${value}`;
      } else if (type === 'month') {
        return `${value}`;
      }
      return value;
    },
    educateList: [{
      id: new Date().getTime(),
      name: '',
      starttime: '请选择',
      endtime: '请选择',
      qualifications: '否',
      special: '',
      remark: '',
    }],
    currentId:''
  },
  schoolNameInput(event) {
    let data = this.data.educateList;
    data.forEach((item) => {
      if (item.id == event.currentTarget.dataset.id) {
        item.name = event.detail
      }
    })
    this.setData({
      educateList: data
    })
  },
  educatestartConfirm(event) {
    console.log(event);
    let self = this;
    let data = this.data.educateList;
    let time = this.formatDate(event.detail);
    var year=time.substring(0,4)
    var month=time.substring(4,6)
    time=year+'-'+month
    data.forEach((item) => {
      if (String(item.id)  ==String(self.data.currentId) ) {
        item.starttime = time
      }
    })
    this.setData({
      educateList: data,
      educatestartShow: false
    })
  },
  educatestartClick(event) {
    console.log(event.currentTarget.dataset.id)
    this.setData({
      currentId: event.currentTarget.dataset.id,
      educatestartShow: true
    })
  },
  educateendClick(event) {
    this.setData({
      currentId: event.currentTarget.dataset.id,
      educateendShow: true
    })
  },
  educateendConfirm(event) {
    let self = this;
    let data = this.data.educateList;
    let time = this.formatDate(event.detail);
    var year=time.substring(0,4)
    var month=time.substring(4,6)
    time=year+'-'+month
    data.forEach((item) => {
      if (String(item.id)  ==String(self.data.currentId) ) {
        item.endtime = time
      }
    })
    this.setData({
      educateList: data,
      educateendShow: false
    })
  },
  educatestartClose() {
    this.setData({
      educatestartShow: false
    })
  },
  educateendClose() {
    this.setData({
      educateendShow: false
    })
  },
  identifycodeBlur(event){
    console.log(event);
    getAnalysisIdCard(event.detail.value)
  },
  havetoChange(event) {
    this.setData({
      havetoActive: event.detail,
    });
  },
  nohaveChange(event) {
    this.setData({
      nohaveActive: event.detail,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  formatDate(date) {
    var date = new Date(date);
    
    var YY = String(date.getFullYear());
    var MM = String((date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1));
    var DD = String((date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()));
    console.log(YY,MM,DD);
    return YY + MM + DD;
  },
})